﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using L = Science.Mathematics.LinearAlgebra;

namespace Strang3Ed.Chapter06.Section1
{
    public class ExampleA
    {
        public ExampleA()
        {
        }
        private string result;
        public string Result
        {
            get { return result; }
        }
        public void Compute()
        {
            double[,] x = { {2.0, -1.0}, 
                           {-1.0, 2.0}};

            L.Matrix A = new L.Matrix(x);

            A.Diagonalize();

            result += A.EigenvalueComplex[0].ToString() + "\r\n";

            result += A.EigenvectorComplex[0].ToString() + "\r\n";

            result += A.EigenvalueComplex[1].ToString() + "\r\n";

            result += A.EigenvectorComplex[1].ToString() + "\r\n";

            L.Matrix AA = A*A;

            AA.Diagonalize();

            result += AA.EigenvalueComplex[0].ToString() + "\r\n";

            result += AA.EigenvectorComplex[0].ToString() + "\r\n";

            result += AA.EigenvalueComplex[1].ToString() + "\r\n";

            result += AA.EigenvectorComplex[1].ToString() + "\r\n";

            L.Matrix Ai = A.Inverse;

            Ai.Diagonalize();

            result += Ai.EigenvalueComplex[0].ToString() + "\r\n";

            result += Ai.EigenvectorComplex[0].ToString() + "\r\n";

            result += Ai.EigenvalueComplex[1].ToString() + "\r\n";

            result += Ai.EigenvectorComplex[1].ToString() + "\r\n";
        }
    }
}
/*
3
0.707106781186547
-0.707106781186547

1
0.707106781186547
0.707106781186547

9
0.707106781186547
-0.707106781186547

1
0.707106781186547
0.707106781186547

1
0.707106781186547
0.707106781186547

0.333333333333333
-0.707106781186547
0.707106781186547
*/

